package com.text;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/servlet05")
public class servlet05 extends HttpServlet {
    /*1创建普通的Java类
    2.实现 servlet的规范，继承httpservlet
       3处理请求（重写servlet方法）
       4.设置注解，指定访问的路径*/
    private String message;
    public void init(){
        System.out.println("1");
        message ="hello world";
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException{
        doGet(req, resp);
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HelloWorld");//打印内容在控制台
        //通过流输出数据到浏览器
        resp.getWriter().write("HelloWorld!");
        PrintWriter out=resp.getWriter();
        out.println("<html><body>");
        out.println("<h1>"+message+"</h1>");
        out.println("</body></html>");
        req.setCharacterEncoding("GBK");
        String input=req.getParameter("input");
        out.println(input);

    }

}
